package com.sixkey.controller.app;

import com.sixkey.entity.Reservation;
import com.sixkey.entity.vo.DeptUserVo;
import com.sixkey.entity.vo.RsAddLengthVo;
import com.sixkey.response.Response;
import com.sixkey.service.IReservationService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * ClassName: ApiReservationController
 * Package: com.sixkey.controller.api
 * Description:
 *
 * @Author: @weixueshi
 * @Create: 2023/10/6 - 0:06
 * @Version: v1.0
 */
@Slf4j
@Validated
@CrossOrigin
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/reservation")
public class ApiReservationController {

    private final IReservationService reservationService;

    /**
     * 保存立即预约会议数据
     * @param reservation
     * @return
     */
    @PostMapping("/save")
    public Response save(@RequestBody @Valid Reservation reservation){
        log.info("保存立即预约会议数据请求进来~");
        reservationService.saveReservation(reservation);
        return Response.success();
    }

    /**
     * 小程序端我的会议数据展示
     * @param
     * @return
     */
    @GetMapping("/list/{authorPhone}")
    public Response list(@PathVariable("authorPhone") String authorPhone){
        log.info("小程序端我的会议数据展示请求进来~");
        List<Reservation> list = reservationService.getReservationList(authorPhone);
        return Response.success(list);
    }

    /**
     * 小程序端预约记录数据展示
     * @param
     * @return
     */
    @GetMapping("/recordList/{authorPhone}")
    public Response getRecordList(@PathVariable("authorPhone") String authorPhone){
        log.info("小程序端预约记录数据展示请求进来~");
        List<Reservation> list = reservationService.getReservationRecordList(authorPhone);
        return Response.success(list);
    }

    /**
     * 会议详情页
     * @param
     * @return
     */
    @GetMapping("/detail/{id}")
    public Response getDetail(@PathVariable("id") int id){
        log.info("小程序端会议详情页数据请求进来~");
        Reservation reservation = reservationService.getDetail(id);
        return Response.success(reservation);
    }

    /**
     * 会议详情页参会人数据
     * @param
     * @return
     */
    @GetMapping("/detail/parts/{id}")
    public Response getDetailParticipants(@PathVariable("id") int id){
        log.info("会议详情页参会人数据请求进来~");
        List<DeptUserVo> list = reservationService.getDetailParticipants(id);
        return Response.success(list);
    }

    /**
     * 取消会议
     * @param
     * @return
     */
    @PostMapping("/cancel/{id}")
    public Response cancel(@PathVariable("id") int id){
        log.info("小程序端取消会议请求进来~");
        reservationService.removeMeetById(id);
        return Response.success();
    }

    /**
     * 延长会议
     * @param
     * @return
     */
    @PostMapping("/addLength")
    public Response addLength(@RequestBody RsAddLengthVo rsAddLengthVo){
        log.info("小程序端延长会议请求进来~");
        reservationService.addLength(rsAddLengthVo);
        return Response.success();
    }

    /**
     * 小程序端根据主题搜索我的会议
     * @param
     * @return
     */
    @GetMapping("/search/{theme}")
    public Response getReservation(@PathVariable("theme") String theme){
        log.info("小程序端根据主题搜索会议请求进来~");
        List<Reservation> list = reservationService.getReservation(theme);
        return Response.success(list);
    }

    /**
     * 小程序端根据主题搜索预约记录会议
     * @param
     * @return
     */
    @GetMapping("/searchRecord/{theme}")
    public Response getReservationRecord(@PathVariable("theme") String theme){
        log.info("小程序端根据主题搜索预约记录会议请求进来~");
        List<Reservation> list = reservationService.getReservationRecord(theme);
        return Response.success(list);
    }
}
